

$(function(){
	
	//提交作品 作品页面更新	 
	$('.previewwork').on('click',".page_save ",function(){
		$("#loadtoast").show();		
		var isflag=checkwork(work_id)//检测作品中所有的图片控件是否都有填充了图片
		//alert(JSON.stringify(isflag))
		if(isflag.complete==false){
			//复制订单编号
			var order_sn = $.cookie('order_no');
			if(/^(E\d{23}|C\d{20})$/.test(order_sn)){
				$(".orderinput").val(order_sn);
			}
			
			$(".previewwork").hide();
			document.title='提交作品';
			$(".submitalbum").show();
			$(".gotoedit").addClass("disablebtn");
			$("#loadtoast").hide();
		}else{
			$("#loadtoast").hide();
			$.alert("填充完整再提交！","提示");	
		}
		
		$(".a_type").html(UtilProperty[work_id].workerInfo.work_name);
		
		
	})
	
	
	//增加印制数量
	$('.submitalbum').on('click',".order_add ",function(){
		var valnum=parseInt($(".order_num").val())+1;
		$(".order_num").val(valnum);
		$('.order_jian').css("color","#838383");
	})
	
	$('.submitalbum').on('click',".order_jian ",function(){
		var valnum=parseInt($(".order_num").val());
		if(valnum>1){
			valnum--;
			$(".order_num").val(valnum);
		}else{
			$(this).css("color","#999");
		}
		
		
	})
	
	
	//提交作品 确认	
	$('.submitalbum').on('click',".comfirm_submit",function(){
		var orderno=$(".orderinput").val();		
		if(orderno==""){
			$(".orderinputtips").html("请填写订单编号");
		}else{
			var oldstatus=UtilProperty[work_id].workerInfo.status;
			var status=oldstatus==0?1:oldstatus;
			var a = {work_id:work_id,order_sn:orderno,status:status,work_number:$(".order_num").val()};
			baseAjax('other/work/update_work','POST',a,function(data){
				if(data.code==200){
					$(".orderinput").val('');
					$.alert('提交成功', "提示");
					if(oldstatus==0){
						UtilProperty[work_id].workerInfo.status=status;
						
						var el=$('.work_itemlist[work_id="'+work_id+'"]');
						var time=el.attr("add_time");
						var box=el.closest(".albumcontain");
						el.attr("status",status);
						if(!el.children().hasClass("copyyes")){					 	
							el.append(' <div class="copyyes"><img src="img/yin.png"></div>')
						}
						var curenthtml = $('.work_itemlist[work_id="'+work_id+'"]').prop("outerHTML");
						 if(!$('.workeritem').children().hasClass('completedwork')){
							$('.workeritem').append('<div class="completedwork"><h6 class="completehr"><span></span></h6></div>');			
				
						}
						if($('.completedwork .workaddtime[time="'+time+'"]').length==0){
							$(".completedwork").append('<div class="weui-cells__title workaddtime" time="'+time+'">'+time+'</div><div class="albumcontain boxflexThu" time="'+time+'"></div>');
						}
						 
						 if(box.children(".albumitem").length==1){									
							box.prev('.workaddtime[time="'+time+'"]').remove();
							box.remove();
							if($(".Not_completedwork").children().length==0){
								$(".Not_completedwork").remove();
							}
						}else{
							el.remove();
						}
						 
						 
						 $('.completedwork .albumcontain[time="'+time+'"]').prepend(curenthtml);
					 
					} 
					 
				 	$(".orderinput").val('');
				 	$(".orderinputtips").html('');
				 	$(".submitalbum").hide();
				 	$(".worker_con").show();
				}
				
			})
		}
		
	})
	
	//返回	
	$('.submitalbum').on('click',".back_submit ",function(){
		if(UtilProperty[work_id].workerInfo.status==0){
			$(".gotoedit").removeClass("disablebtn");
		}
		$(".previewwork").show();
		$(".submitalbum").hide();
	})
	
	
	
	
})
